<!DOCTYPE html>
<!-- saved from url=(0052)http://getbootstrap.com/docs/4.0/examples/dashboard/ -->
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>员工管理</title>
    <!-- Bootstrap core CSS -->
    <link href="asserts/css/bootstrap.min.css" th:href="@{/webjars/bootstrap/4.0.0/css/bootstrap.css}" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="../../static/asserts/css/dashboard.css" rel="stylesheet" th:href="@{/asserts/css/dashboard.css}">
    <link href="../../static/layui/2.8.0/css/layui.css" th:href="@{/layui/css/layui.css}" rel="stylesheet">
    <style type="text/css">
        /* Chart.js */

        @-webkit-keyframes chartjs-render-animation {
            from {
                opacity: 0.99
            }
            to {
                opacity: 1
            }
        }

        @keyframes chartjs-render-animation {
            from {
                opacity: 0.99
            }
            to {
                opacity: 1
            }
        }

        .chartjs-render-monitor {
            -webkit-animation: chartjs-render-animation 0.001s;
            animation: chartjs-render-animation 0.001s;
        }
    </style>
    <style>
        #span_page {
            font-size: 30px;
            margin-left: 15px;

        }

        .span_select {
            font-size: 20px;
            color: black;
        }
    </style>
</head>

<body>
<!--引入顶部栏-->
<div th:replace="commons/bar::topbar"></div>
<div class="container-fluid">
    <div class="row">
        <!--引入侧边栏-->
        <div th:replace="commons/bar::sidebar(activeUri='emps')"></div>
        <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
            <!-- 条件搜索框 -->
            <form action="#" method="get" th:action="@{/emps}">
                <p><span class="span_select">姓名:</span> <input type="text" name="lastName" placeholder="请输入姓名">
                    <span class="span_select">部门:</span>
                    <select type="" name=deptId>
                        <option th:value="0">----请选择----</option>
                        <option th:each="dept:${depts}" th:value="${dept.id}">[[${dept.id}+${dept.departmentName}]]
                        </option>
                    </select>
                <button type="submit" class="btn btn-primary">查询</button>
                </p>
            </form>

            <!--  创建时间 between #{beginTime} and #{endTime}保证数据去重
                  >= #{beginTime} and <= #{endTime} 保证索引查询不会失效 -->
            <div class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <span class="span_select">创建时间:</span>
                        <div class="layui-inline" id="ID-laydate-range">
                            <div class="layui-input-inline">
                                <input type="text" name="beginTime" autocomplete="off" id="ID-laydate-start-date" class="layui-input" placeholder="开始日期">
                            </div>
                            <div class="layui-form-mid">-</div>
                            <div class="layui-input-inline">
                                <input type="text" name="endTime" autocomplete="off" id="ID-laydate-end-date" class="layui-input" placeholder="结束日期">
                            </div>
                        </div>
                    </div>
                </div>

            </div>

            <h2><a class="btn btn-sm btn-success" th:href="@{/emp}">添加员工</a>
                <a class="btn btn-sm btn-danger" th:attr="uri=@{/emps}" id="delAll" href="#">批量删除</a>
                <button class="btn btn-light">导出</button>
            </h2>
            <div class="table-responsive">
                <table class="table table-striped table-sm">
                    <thead>
                    <tr>
                        <th><input type="checkbox" id="th_checkbox"></th>
                        <th>序号</th>
                        <th>编号</th>
                        <th>姓名</th>
                        <th>邮箱</th>
                        <th>性别</th>
                        <th>部门</th>
                        <th>生日</th>
                        <th>入职日期</th>
                        <th>员工薪资</th>
                        <th>创建时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <form id="delSelected" action="#" method="post">
                        <input type="hidden" name="_method" value="delete">
                        <tr th:each="emp:${pb.records}">
                            <td><input type="checkbox" class="td_checkbox" name="eid" th:value="${emp.id}"></td>
                            <!--使用emp来遍历emps，所以其默认状态变量为：empStat,empStat.count实现循环时递增序号-->
                            <td th:text="${empStat.count}"></td>
                            <td th:text="${emp.id}"></td>
                            <td th:text="${emp.lastName}"></td>
                            <td th:text="${emp.email}"></td>
                            <td th:text="${emp.gender}=='0'?'女':'男'"></td>
                            <td th:text="${emp.deptId}"></td>
                            <td th:text="${#dates.format(emp.birth,'yyyy-MM-dd')}"></td>
                            <td th:text="${#dates.format(emp.hireDate,'yyyy-MM-dd')}"></td>
                            <td th:text="${emp.salary}"></td>
                            <td th:text="${#dates.format(emp.createTime,'yyyy-MM-dd')}"></td>
                            <td>
                                <a type="button" class="btn-sm btn-primary" th:href="@{/emp/}+${emp.id}">编辑</a>
                                <!-- 删除单个员工 th:attr="action=@{/subscribe} 改变属性的值 -->
                                <button class="btn-sm btn-danger deleteBtn" th:attr="uri=@{/emp/}+${emp.id}">删除</button>
                            </td>
                        </tr>
                    </form>
                    </tbody>
                </table>
                <div>
                    <!-- 分页导航条
                       前端传递的参数：
                          1、当前页码：currentPage
                          2、每页显示的条数：pageSize
                       后端需要响应的参数：
                          1、当前页记录(集合)：records
                          2、总记录数：totalRecords
                    -->
                    <nav aria-label="Page navigation example">
                        <ul class="pagination">
                            <li>
                                <span id="span_page"> 共 <span
                                        style="color: #ed181b">[[${pb.totalPage}]]</span> 页,  共<span
                                        style="color: #ed181b">[[${pb.totalCount}]]</span> 条记录 </span>
                            </li>
                            <li class="page-item">
                                <a class="page-link" href="#"
                                   th:href="@{/emps(currentPage=${pb.currentPage}-1,pageSize=5,name=${emp.lastName},gender=${emp.gender},deptId=${emp.deptId})}"
                                   aria-label="Previous">
                                    <span aria-hidden="true">&laquo;</span>
                                </a>
                            </li>

                            <th:block th:each="page:${#numbers.sequence(1,pb.totalPage)}">
                                <li class="page-item "
                                    th:class="${(pb.currentPage==page)?'page-item active':'page-item'}"><a
                                        class="page-link" href="#"
                                        th:href="@{/emps(currentPage=${page},pageSizes=5,lastName=${emp.lastName},gender=${emp.gender},deptId=${emp.deptId})}"
                                        th:text="${page}"></a></li>
                            </th:block>
                            <li class="page-item">
                                <a class="page-link" href="#"
                                   th:href="@{/emps(currentPage=${pb.currentPage}+1,pageSizes=5,lastName=${emp.lastName},gender=${emp.gender},deptId=${emp.deptId})}"
                                   aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                </a>
                            </li>
                            <li>
                                <span id="span_page"> 当前第 <span
                                        style="color: #ed181b">[[${pb.currentPage}]]</span> 页 </span>
                            </li>
                        </ul>
                    </nav>
                </div>
            </div>
        </main>
        <!-- 删除单个员工 -->
        <form id="delForm" action="#" method="post">
            <input type="hidden" name="_method" value="DELETE">
        </form>
    </div>
</div>

<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script type="text/javascript" src="asserts/js/jquery-3.2.1.slim.min.js"
        th:src="@{/webjars/jquery/3.3.1/jquery.js}"></script>
<script type="text/javascript" src="asserts/js/popper.min.js"
        th:src="@{/webjars/popper.js/1.11.1/dist/popper.js}"></script>
<script type="text/javascript" src="asserts/js/bootstrap.min.js"
        th:src="@{/webjars/bootstrap/4.0.0/js/bootstrap.js}"></script>
<script src="/cdn.staticfile.org/layui/2.8.0/layui.js" th:src="@{/layui/layui.js}"></script>

<!-- Icons -->
<script type="text/javascript" src="../../static/asserts/js/feather.min.js"
        th:href="@{/asserts/js/feather.min.js}"></script>
<script>
    feather.replace()
</script>

<!-- Graphs -->
<script type="text/javascript" src="../../static/asserts/js/Chart.min.js"
        th:href="@{/asserts/js/Chart.min.js}"></script>
<script>
    var ctx = document.getElementById("myChart");
    var myChart = new Chart(ctx, {
        type: 'line',
        data: {
            labels: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
            datasets: [{
                data: [15339, 21345, 18483, 24003, 23489, 24092, 12034],
                lineTension: 0,
                backgroundColor: 'transparent',
                borderColor: '#007bff',
                borderWidth: 4,
                pointBackgroundColor: '#007bff'
            }]
        },
        options: {
            scales: {
                yAxes: [{
                    ticks: {
                        beginAtZero: false
                    }
                }]
            },
            legend: {
                display: false,
            }
        }
    });
</script>
<script>
    /**删除功能*/
    $(".deleteBtn").click(function () {
        //删除当前员工
        if (confirm("您确定要删除吗？")) {
            $("#delForm").attr("action", $(this).attr("uri")).submit();
            return false;
        }
    });
</script>
<script>
    /**全选功能*/
    $("#th_checkbox").click(function () {
        $(".td_checkbox").attr("checked", this.checked);
    });

    /**删除选中：给删除选中按钮绑定单击事件，点击提交表单，携带删除的员工id*/
    $("#delAll").click(function () {

        if (confirm("您确定要删除所有选中吗？")) {

            $("#delSelected").attr("action", $(this).attr("uri")).submit();
            return false;
        }
    });

</script>

<script>
    layui.use(function () {
        var laydate = layui.laydate;
        // 创建时间 - 左右面板独立选择模式
        laydate.render({
            elem: '#ID-laydate-range',
            range: ['#ID-laydate-start-date', '#ID-laydate-end-date']
        });

    });
</script>

<script>
    layui.use(function () {
        var layer = layui.layer;
        // Welcome
        layer.msg('Hello World', {icon: 6});
    });
</script>


</body>

</html>